package org.whz.configuration;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author whz-dell
 */
@Configuration
@EnableConfigurationProperties(HazelcastProperties.class)
public class HazelcastConfiguration {
    @Bean
    @ConditionalOnMissingBean(HazelcastProperties.class)
    public HazelcastProperties createHazelcastProperties() {
        return new HazelcastProperties();
    }

    @Bean
    @ConditionalOnBean(DiscoveryClient.class)
    public HazelcastConfig createHazelcastConfig(DiscoveryClient discoveryClient, HazelcastProperties hazelcastProperties) {
        return new HazelcastConfig(discoveryClient, hazelcastProperties);
    }
}